package edu.snake.implement.model.character.movement;

import edu.snake.core.model.character.Course;
import edu.snake.implement.model.arena.Direction;


public class CourseImplSnake implements Course {

    protected Direction new_direction;
    protected Direction course;

    public CourseImplSnake() {
        course = Direction.RIGHT;
        new_direction = Direction.EMPTY;
    }

    @Override
    public void setDirection(Direction direction) {
        this.new_direction = direction;
    }

    @Override
    public Direction getCourse() {
        return course;
    }

    @Override
    public Direction calculateCourse() {
        switch (course) {
            case UP:
                if (new_direction == Direction.LEFT) {
                    this.course = Direction.LEFT;
                } else if (new_direction == Direction.RIGHT) {
                    this.course = Direction.RIGHT;
                }
                break;
            case DOWN:
                if (new_direction == Direction.LEFT) {
                    this.course = Direction.RIGHT;
                } else if (new_direction == Direction.RIGHT) {
                    this.course = Direction.LEFT;
                }
                break;

            case LEFT:
                if (new_direction == Direction.LEFT) {
                    this.course = Direction.DOWN;
                } else if (new_direction == Direction.RIGHT) {
                    this.course = Direction.UP;
                }
                break;

            case RIGHT:
                if (new_direction == Direction.LEFT) {
                    this.course = Direction.UP;
                } else if (new_direction == Direction.RIGHT) {
                    this.course = Direction.DOWN;
                }
                break;
        }
        new_direction = Direction.EMPTY;
        return course;
    }

    @Override
    public String toString() {
        return "CourseImplSnake{}";
    }
}
